package controller;
import entity.Score;
import entity.TestsPaper;
import entity.User;
import service.TestsOpt;
import service.UserOpt;
import view.*;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

public class MyController {
    /**
     * 用户登录验证
     * @param login： 登录界面
     * @param name
     * @param password
     * @return
     * @throws IOException
     */
    public static Home UserLoginCheck(UserLogin login,String name, String password) throws IOException {
        if (UserOpt.LoginCheck(name, password)){         // 密码验证成功
            return new Home(login,name);               // 返回主界面
        }
        return null;
    }

    /**
     * 用户注册处理
     * @param user
     * @return
     * @throws IOException
     */
    public static boolean UserRegister(User user) throws IOException {
        return UserOpt.UserRegister(user);
    }
    /**
     * 获取用户成绩
     * @param name
     * @return
     * @throws IOException
     */
    public static List<Score> getUserScore(String name) throws IOException {
        return UserOpt.getUserScore(name);
    }

    /**
     * 更新用户成绩
     * @param name
     * @param score
     * @return
     * @throws IOException
     */
    public static void updUserScore(String name,String testName,int score) throws IOException {
        UserOpt.updUserScore(name,testName,score);
    }

    /**
     * 根据试题行获取一道试题
     * @param row
     * @return
     */
    public static TestsPaper getTestByRow(int row){
        return TestsOpt.getTestByRow(row);
    }

    /**
     * 获取试题数量
     * @return
     * @throws IOException
     */
    public static int getTotalSum() throws IOException {
        return TestsOpt.getTotalSum();
    }

    /**
     * 返回考试准则页面
     * @return
     */
    public static ExamRules getExamRules() throws FileNotFoundException {
        return TestsOpt.getExamRules();
    }

    /**
     * 返回考试界面
     * @param home
     * @param name
     * @return
     * @throws IOException
     */
    public static TestsMain getTestsMain(Home home,String name) throws IOException {
        return new TestsMain(home,name);
    }

    /**
     * 返回注册页面
     * @return
     */
    public static Register getRegister(){
        return new Register();
    }

    /**
     * 返回个人成绩视图
     * @param name
     * @return
     * @throws IOException
     */
    public static UserScoreShow getUserScoreShow(String name) throws IOException {
        return new UserScoreShow(name);
    }
}
